package com.yanqu.road.server.cmd.activity.tanghulu;


import com.yanqu.road.pb.activity.TangHuLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.tanghulu.TangHuLuModule;
import com.yanqu.road.server.manger.activity.tanghulu.TangHuLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

//@Cmd(code = Protocol.S_TANGHULU_ACTIVITY_FAST_MAKE, desc = "糖葫芦-快速制作")
public class TangHuLuFastMakeCmd extends AbstractCommand {

    int goodsId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        TangHuLuProto.TangHuLuFastMakeReqMsg reqMsg = TangHuLuProto.TangHuLuFastMakeReqMsg.parseFrom(packet.getBytes());
        goodsId = reqMsg.getGoodsId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(TangHuLuMgr.getShowTimeActivityId() == 0){
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if(!TangHuLuMgr.activityInTime()){
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        //判定水果道具是否有效
        if(goodsId != TangHuLuMgr.TANGHULU_CARAMBOLA_ID && goodsId != TangHuLuMgr.TANGHULU_HAWTHORN_ID &&
                goodsId != TangHuLuMgr.TANGHULU_KIWIFRUIT_ID && goodsId != TangHuLuMgr.TANGHULU_STRAWBERRY_ID){
            ret = GameErrorCode.E_COMMON_ACTIVITY_NO_ACTIVITY_GOODS;
            return;
        }

        ret = player.getModule(TangHuLuModule.class).fastMake(goodsId);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            TangHuLuProto.TangHuLuFastMakeRespMsg.Builder respMsg = TangHuLuProto.TangHuLuFastMakeRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_TANGHULU_ACTIVITY_FAST_MAKE, respMsg);
        }
    }
}
